---
date: 2022-07-13 14:00
description: Learn how to enable query logging in Fluent to see the generated SQL queries
tags: Fluent, tips
author: Tim
authorImageURL: /author-images/tim.jpg
---
# Enable SQL Query Logging

The Fluent drivers log the SQL they generate at the debug log level. This allows you to opt in to seeing the SQL generated without making it too noisy. This also follow the guidance from the SSWG on [library logging](https://github.com/swift-server/guides/blob/main/docs/libs/log-levels.md). 

Some drivers, like FluentPostgreSQL, allow this to be configured when you configure the database. For example:

```swift
app.databases.use(.postgres(
    hostname: Environment.get("DATABASE_HOST") ?? "localhost",
    port: Environment.get("DATABASE_PORT").flatMap(Int.init(_:)) ?? PostgresConfiguration.ianaPortNumber,
    username: Environment.get("DATABASE_USERNAME") ?? "vapor_username",
    password: Environment.get("DATABASE_PASSWORD") ?? "vapor_password",
    database: Environment.get("DATABASE_NAME") ?? "vapor_database",
    sqlLogLevel: .info
), as: .psql)
```

That would log SQL statements at the info level.

To set the log level, in configure.swift (or where you set up your application) add:

```swift
app.logger.logLevel = .debug
```

This sets the log level to debug. When you next build and run your app, the SQL statements generated by Fluent will be logged to the console.
